<template>
    <section>
    </section>
</template>

<script>
    export default {
      name:'callBack',
      data(){
          return{

          }
      },
      created(){

        function getParams(url) {

          var theRequest = new Object();
          if (!url)
            url = location.href;
          if (url.indexOf("?") !== -1) {
            var str = url.substr(url.indexOf("?") + 1) + "&";
            var strs = str.split("&");
            for (var i = 0; i < strs.length - 1; i++) {
              var key = strs[i].substring(0, strs[i].indexOf("="));
              var val = strs[i].substring(strs[i].indexOf("=") + 1);
              theRequest[key] = val;
            }
          }
          return theRequest;
        }
        const code =  getParams().code;
        const state = getParams().state;
        const that  = this;

        setTimeout(()=>{
          that.$ajax.post(window.g.apiUrl+'/user/keepLog.do',JSON.stringify({
            code:code,
          })).then((response)=>{
            if(state == 'INDEX#/callback'){
              if(response.data.code == 200){
                localStorage.setItem('userid',response.data.data)
                that.$router.replace('/index')
              }else{
                that.$router.replace('/index')
              }
            }else if(state == 'MINE#/callback'){
              if(response.data.code == 200){
                localStorage.setItem('userid',response.data.data)
                that.$router.replace('/mine')
              }else{
                that.$router.replace('/login')
              }
            }else if(state == 'RECHARGE#/callback'){
              if(response.data.code == 200){
                localStorage.setItem('userid',response.data.data)
                that.$router.replace('/recharge')
              }else{
                that.$router.replace('/login')
              }
            }
          }).catch(()=>{
          })
        },100)
      }
    }
</script>

<style scoped>

</style>
